import 'package:flutter/cupertino.dart';
import 'package:learning_content_admin_pannel.core/core/domain/entities/page_models/app_navigator_page_model.dart';

class AppNavigatorPage<T> extends Page<T> {
   AppNavigatorPage({
    required this.pageModel,
    required this.child,
    this.maintainState = true,
    this.fullscreenDialog = false,
    this.opaque = true,
    super.name,
    super.arguments,
  }) : super(key: ValueKey(pageModel.id));

  final AppNavigatorPageModel pageModel;

  final Widget child;
  final bool maintainState;
  final bool fullscreenDialog;
  final bool opaque;

  @override
  Route<T> createRoute(BuildContext context) {
    return _PageBasedPageRoute<T>(page: this);
  }
}

class _PageBasedPageRoute<T> extends PageRoute<T>
    with CupertinoRouteTransitionMixin<T> {
  _PageBasedPageRoute({
    required AppNavigatorPage<T> page,
  }) : super(settings: page);

  @override
  String? get title => null;

  @override
  bool get opaque => _page.opaque;

  AppNavigatorPage<T> get _page => settings as AppNavigatorPage<T>;

  @override
  Widget buildContent(BuildContext context) {
    return _page.child;
  }

  @override
  bool get maintainState => _page.maintainState;

  @override
  bool get fullscreenDialog => _page.fullscreenDialog;

  @override
  String get debugLabel => '${super.debugLabel}(${_page.name})';
}
